<template>
  <div id="trans-histories" class="mt-5">
    <div class="card">
      <div class="card-header">交易记录</div>
    </div>
    <div id="divFlightInfo">
      <div class="card">
        <div class="card-body">
          <form class="" id="frmSearchTransHistory">
            <input
              type="hidden"
              id="frmSearchTransHistory_sc_pageNo"
              name="sc.pageNo"
              v-model.number="sc.pageNo"
            />
            <input
              type="hidden"
              id="frmSearchTransHistory_sc_pageSize"
              name="sc.pageSize"
              value="20"
            />
            <input
              type="hidden"
              id="frmSearchTransHistory_sc_enterpriseId"
              name="sc.enterpriseId"
              value="0"
            />

            <div class="col-1 hidden">
              <input
                type="text"
                class="form-control"
                id="frmSearchTransHistory_sc_remark"
                name="sc.remark"
                placeholder="备注"
                size="10"
                v-model.trim="remark"
              />
            </div>
            <div class="col-1">
              <select
                class="form-control"
                id="frmSearchTransHistory_sc_type"
                name="sc.type"
                v-model.number="type"
              >
                <option value="0">现金账户</option>
                <option value="1">积分账户</option>
              </select>
            </div>
            <div class="col-1">
              <select
                class="form-control"
                id="frmSearchTransHistory_sc_status"
                name="sc.status"
                v-model.number="status"
              >
                <option value="-1" selected>全部</option>
                <option value="1">tmc订单</option>
                <option value="2">tmc退票单</option>
              </select>
            </div>
            <button
              type="button"
              class="btn btn-primary"
              @click.stop="search()"
            >
              查找
            </button>
          </form>
        </div>
      </div>
      <table class="table table-striped table-hover table-sm">
        <thead>
          <tr>
            <th>时间a</th>
            <th>存入</th>
            <th>支出</th>
            <th>余额(元)</th>
            <th>备注</th>
          </tr>
        </thead>
        <tbody>
          <template v-for="info in dataList">
            <tr :key="info.id">
              <td>{{ info.createTime }}</td>
              <td>
                <span v-if="info.credit > 0">{{ info.credit / 100 }}</span>
              </td>
              <td>
                <span v-if="info.debt > 0">{{ info.debt / 100 }}</span>
              </td>
              <td>{{ info.accountBalance / 100 }}</td>
              <td>{{ info.remark }}</td>
            </tr>
          </template>
        </tbody>
      </table>
      <nav id="pagination-box" class="float-end">
        <my-pagination
          name="pagination"
          :row-count="sc.rowCount"
          :page-total="sc.pageTotal"
          :page-no="sc.pageNo"
          @next-page="nextPage"
          @prev-page="prevPage"
          @direct-page="directPage"
        ></my-pagination>
      </nav>
    </div>
  </div>
</template>

<script>
import MyPagination from "@/components/my-pagination.vue";
import { APP_FLIGHT_PATH } from "@/common/common.js";
import $ from "jquery";

export default {
  components: {
    MyPagination,
  },
  data() {
    return {
      sc: {
        rowCount: 0,
        pageNo: 1,
        pageSize: 15,
        pageTotal: 0,
      },
      enterpriseId: 0,
      remark: "",
      type: 0,
      status: -1,

      dataList: [],
    };
  },
  mounted: function () {
    this.search();
  },
  methods: {
    search: function () {
      const self = this;
      const params = {
        "sc.pageNo": this.sc.pageNo,
        "sc.pageSize": this.sc.pageSize,
        "sc.enterpriseId": this.enterpriseId,
        "sc.remark": this.remark,
        "sc.type": this.type,
        "sc.status": this.status,
      };
      $.ajax({
        type: "post",
        url: APP_FLIGHT_PATH + "/searchTransactionHistory.do",
        data: params,
        dataType: "json",
        success: function (jsonResult) {
          self.dataList = jsonResult.dataList;
          self.sc = jsonResult.page;
        },
      });
    },
    prevPage: function () {
      this.sc.pageNo = this.sc.pageNo - 1;
      if (this.sc.pageNo < 1) this.sc.pageNo = 1;
      this.search();
    },
    nextPage: function () {
      this.sc.pageNo = this.sc.pageNo + 1;
      this.search();
    },
    directPage: function (pageNo) {
      this.sc.pageNo = pageNo;
      this.search();
    },
  },
};
</script>